<template>
  <Modal 
      :mask-closable="false"
      v-model="toggle"
      :title="`${$t('common.Approval')}`"
      class="modal-content-layout"
      >
    <div>
      <Form
          :show-message="false"
          label-position="top"
      >
        <FormItem>
          <template #label>
            <span style="color: red">*</span>
            <span>{{ $t('equipmentscrapped.Result') }}</span>
          </template>
          <RadioGroup v-model="form.result">
            <Radio :label=4>{{ $t('通过') }}</Radio>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <Radio :label=5>{{ $t('不通过') }}</Radio>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <Radio :label=6>{{ $t('退回') }}</Radio>
          </RadioGroup>
        </FormItem>
<!--        <FormItem v-if="form.result/1===4">-->
<!--          <template #label>-->
<!--            <span style="color: red">*</span>-->
<!--            <span>{{ $t('equipmentscrapped.ReturnTo') }}</span>-->
<!--          </template>-->
<!--          <RadioGroup v-model="form.rollbackRole">-->
<!--            <Radio label="申请人">{{ $t('ledger.AppliedBy') }}</Radio>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
<!--            <Radio v-if="userRoleName==='财务总监' || userRoleName ==='总经理'" label="财务经理">财务经理</Radio>-->
<!--          </RadioGroup>-->
<!--        </FormItem>-->
        <FormItem>
          <template #label>
            <span style="color: red">*</span>
            <span>{{ $t('equipmentscrapped.Comments') }}</span>
          </template>
          <Input type="textarea" v-model="form.scrapApprovalMessage" :placeholder="`${$t('common.inputInfo')}`"/>
        </FormItem>
      </Form>
    </div>
    <div slot="footer">
      <Button type="default" @click="toggle = false">{{ $t('common.Cancle') }}</Button>
      <Button type="primary" :loading="loading" @click="submit">{{ $t('maintenance.Confirmed') }}</Button>
    </div>
  </Modal>
</template>

<script>
// import fileDownload from "js-file-download";

export default {
  name: "approval",
  props: ['show', 'row'],
  data() {
    return {
      toggle: false,
      loading: false,
      form: {},
      userRoleName:{}
    }
  },
  watch: {
    show: function (val) {
      if (val) {
        this.toggle = val
      }
    },
    toggle: function (val) {
      if (!val) {
        this.form = {}
        this.$emit('update:show', val)
      }
    }
  },
  mounted() {
    this.userRoleName = window.localStorage.getItem('ziyunFactoryUserRoleName')
  },
  methods: {
    submit() {
      const params = this.form;
      const {result,scrapApprovalMessage} = params;
      if (!result){
        this.$Message.error('请选择审批结果！')
        return;
      }
      // if (!rollbackRole && result/1===4){
      //   this.$Message.error('请选择退回角色！')
      //   return;
      // }
      if (!scrapApprovalMessage){
        this.$Message.error('请输入审批意见！')
        return;
      }
      params.deviceScrapApprovalId = this.row.deviceScrapApprovalId
      params.deviceScrapApplyId = this.row.id
      params.approvalRole = localStorage.getItem('ziyunFactoryUserRoleId')
      // if (result/1!==4){
      //   delete params.rollbackRole
      // }
      this.axios({
        method: 'post',
        url: '/dms/scrapApply/doApproval',
        data: params
      }).then(res => {
        if (res.code === 200) {
          this.toggle = false
          this.$emit('change')
        }
      })
    }
  }
}
</script>
<style></style>


